import type { DataTableColumn as TableCol } from "naive-ui";
import { VNodeChild } from "vue";

export interface ReqParams {
  page?: number;
  pageSize?: number;
}

export type DataTableColumn<T = any> = TableCol<T> & {
  key: string;
  title: string;
  titleRender?: () => VNodeChild;
  canEdit?: boolean;
  lock?: boolean;
};

export interface TableColumn {
  key: string;
  title: string;
  align?: "left" | "right" | "center";
  fixed?: "left" | "right" | boolean;
}

export interface RespPage {
  records: any[];
  totalRow: number;
}

export interface PaginationProps {
  page: number;
  pageSize: number;
  pageSizes?: number[];
  itemCount?: number;
  pageSlot?: number; // 页码显示的个数
}

export type RequestPage =
  | (() => Promise<RespPage | any[] | undefined | void>)
  | ((params: ReqParams) => Promise<RespPage | any[] | undefined | void>);

export interface DataTableProps {
  columns: DataTableColumn[];
  checkedKeys?: string[];
  request: RequestPage;
  rowKey?: (row: any) => string;
  remote?: boolean;
  striped?: boolean;
  singleLine?: boolean;
  pagination?: PaginationProps;
  maxHeight?: number | string;
  minHeight?: number | string;
  scrollX?: number | string;
  size?: "small" | "medium" | "large";
}

export interface DataTableEmits {
  (e: "update:data", p: any[]): void;
  (e: "update:checkedKeys", p: any[]): void;
}
